import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class SaveDao {


    //保存的数据库
    public void saveFileInfo(String fileName, String filePath) {
        // 数据库连接信息
        String url = "jdbc:mysql://localhost:3306/spring?characterEncoding=utf8&useSSL=false";
        String user = "root";
        String password = "dddd";


        try {
            Class.forName("com.mysql.jdbc.Driver");

            String sql = "insert into file (file_name,file_path,upload_time) values (?,?,?)";

            Connection conn = DriverManager.getConnection(
                    url,
                    user,
                    password);
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,fileName);
            ps.setString(2,filePath);
            ps.setTimestamp(3, new java.sql.Timestamp(new Date().getTime()));

            //执行SQL语句
            ps.executeUpdate();

            //关闭连接
            ps.close();
            conn.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }



    }

}
